package com.jzo2o.customer.controller.agency;


import com.jzo2o.customer.model.dto.request.InstitutionResetPasswordReqDTO;
import com.jzo2o.customer.model.dto.response.ServeProviderInfoResDTO;
import com.jzo2o.customer.service.IServeProviderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 服务人员/机构表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-17
 */
@RestController("agencyServeProviderController")
@RequestMapping("/agency/serve-provider")
@Api(tags = "机构端 - 服务人员或机构相关接口")
@RequiredArgsConstructor
public class ServeProviderController {
    @Resource
    private IServeProviderService serveProviderService;
    private final PasswordEncoder passwordEncoder;


    @GetMapping("/currentUserInfo")
    @ApiOperation("获取当前用户信息")
    public ServeProviderInfoResDTO currentUserInfo() {
        return serveProviderService.currentUserInfo();
    }

    // @Valid注解作用：对于传递过来的DTO入参进行@NotNull 约束注解进行校验，如果违反错误就会报错；这样做的好处就是避免在业务代码中使用if来判断校验
    @PostMapping("/institution/resetPassword")
    @ApiOperation("机构登录密码重置接口")
    public void resetPassword(@Valid @RequestBody InstitutionResetPasswordReqDTO institutionResetPasswordReqDTO) {
        String encodePass = passwordEncoder.encode(institutionResetPasswordReqDTO.getPassword());
        serveProviderService.resetPassword(institutionResetPasswordReqDTO.getPhone(), encodePass, institutionResetPasswordReqDTO.getVerifyCode());
    }
}
